home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / Hydra11s.lha / HBBS / Source / Doors_System / ErrorMessage / ErrorMesssage.C < prev    next >
C/C++ Source or Header  |  1996-10-31  |  5KB  |  207 lines

  1. /*
  2.  
  3.    ErrorMessage (C) 1995 Hydra/TSN
  4.  
  5.    Usage:  ErrorMessage <n>  where <n> is the number of the error message
  6.            contained in the file HBBS:Doors/System/ErrorMessage/ErrorMessage.TXT
  7.  
  8.    This program is called by the main program when it encounters an error,
  9.    it's done like this to a) save having all the error message strings loaded in
  10.    memory at one time b) to save code size of main program c) cos it's cool
  11.    and d) so that you can have really long error messages when can contain
  12.    solution descriptions.
  13.  
  14.    e.g.
  15.  
  16.    2=There's an error in you HBBS:Nodes/NodeList file or your HBBS:BBSGlobal file, you have specified more nodes in BBSNodes=x than you have parameters for NodeList_XX=X
  17.  
  18.    see what i mean ?
  19.  
  20.  
  21.    todo
  22.    ====
  23.  
  24.    update so that it will find hbbs's screen if hbbs is not using either workbench or it's own
  25.    custom screen (i.e. any other public screen!)
  26. */
  27.  
  28. #define ERRORMESSAGE
  29. #define MAIN
  30.  
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <string.h>
  34. #include <exec/exec.h>
  35. #include <clib/exec_protos.h>
  36. #include <libraries/reqtools.h>
  37. #include <clib/reqtools_protos.h>
  38.  
  39. #include <intuition/intuition.h>
  40. #include <clib/intuition_protos.h>
  41.  
  42. #include <ctype.h>
  43.  
  44. #include <HBBS/Defines.h>
  45. #include <HBBS/types.h>
  46. #include <HBBS/structures.h>
  47. #include <HBBS/hbbscommon_protos.h>
  48. #include <HBBS/hbbscommon_pragmas.h>
  49. #include <HBBS/release.h>
  50. char *versionstr="$VER: ErrorMessage "RELEASE_STR;
  51.  
  52. #include "//common/files.h"
  53.  
  54. struct Library *HBBSCommonBase=NULL;
  55. struct ReqToolsBase *ReqToolsBase; // define globallaly or stack overflow away! :-)
  56. // struct BBSGlobalData *BBSGlobal=NULL;
  57.  
  58. long __stack=10000;
  59.   struct Screen *scr=NULL;
  60.   struct Process *myproc=NULL;
  61.   struct Window *oldwinptr=NULL;
  62.  
  63.  
  64. static VOID cleanup(ULONG num)
  65. {
  66.   if (HBBSCommonBase)
  67.   {
  68.     HBBS_CleanUpCommon();
  69.     CloseLibrary (HBBSCommonBase);
  70.   }
  71.  
  72.   if (num) printf("Door Error = %d\n",num);
  73.  
  74.   if (ReqToolsBase)
  75.     CloseLibrary ((struct Library *)ReqToolsBase);
  76.  
  77.   exit(0);
  78. }
  79.  
  80. static VOID init(VOID)
  81. {
  82.   if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
  83.   {
  84.     cleanup(1);
  85.   }
  86.  
  87.   if (!(HBBS_InitCommon()))
  88.   {
  89.     cleanup(2);
  90.   }
  91.  
  92.   if (ReqToolsBase = (struct ReqToolsBase *) OpenLibrary (REQTOOLSNAME, REQTOOLSVERSION))
  93.   {
  94.  
  95.     // lock the ctrlscrn, if that's not there then get the wb screen. if thats not there
  96.     // then we'll just go argh!
  97.  
  98.     if ((scr=LockPubScreen("CtrlScrn")) || (scr=LockPubScreen(NULL))) // get screen
  99.     {
  100.       if (scr->FirstWindow) // get
  101.       {
  102.         if (myproc=(struct Process *)FindTask(NULL))
  103.         {
  104.           oldwinptr = myproc->pr_WindowPtr;
  105.           myproc->pr_WindowPtr=scr->FirstWindow;
  106.         }
  107.       }
  108.  
  109.     }
  110.   }
  111.  
  112. }
  113.  
  114. void main(int argc, char *argv[])
  115. {
  116.   char *cantfind="An error has occured but I can't find the message text!";
  117.  
  118.   FILE *errfile;
  119.   char errline[2048];
  120.   char errormsg[2048];
  121.   char errstr[1024];
  122.   char item[20];
  123.   BOOL found=FALSE;
  124.  
  125.   BOOL setcr=FALSE;
  126.   int loop;
  127.  
  128.   if (argc==1)
  129.   {
  130.     puts("ErrorMessage V1.1 (C) 1996 Hydra/LSD, This program is part of HBBS!");
  131.     puts("Usage: ErrorMessage <NUMBER> <NODE> [<STR..>]");
  132.   }
  133.   else
  134.   {
  135.     init();
  136.     // if we have reqtools.library then set the requester default window to the first window on ctrlscrn!
  137.  
  138.     if (errfile=fopen(FILE_ERRORMESSAGE,"r"))
  139.     {
  140.       while (!feof(errfile) && !found)
  141.       {
  142.         fgets(errline,1000,errfile);
  143.         if (!feof(errfile))
  144.         {
  145.           stripcr(errline);
  146.           GetItem(item,errline);
  147.           if (stricmp(item,argv[1])==0)
  148.           {
  149.             found=TRUE;
  150.           }
  151.         }
  152.       }
  153.       fclose(errfile);
  154.     }
  155.  
  156.     if (found)
  157.     {
  158.       for (loop=3;loop<argc;loop++)
  159.       {
  160.         if (loop!=3)
  161.         {
  162.           strcat(errstr," ");
  163.           strcat(errstr,argv[loop]);
  164.         }
  165.         else
  166.         {
  167.           strcpy(errstr,argv[loop]);
  168.         }
  169.       }
  170.       GetParams(errormsg,errline);
  171.       if (argc>=3) replace(errormsg,errormsg,"@N@",argv[2]);
  172.       if (argc==4) replace(errormsg,errormsg,"@E@",errstr);
  173.  
  174.       for (loop=0;loop<strlen(errormsg);loop++)
  175.       {
  176.         if ((loop % 70)==69) // insert a cariage return every 70 chars if possible
  177.         {
  178.           setcr=TRUE;
  179.         }
  180.         if (setcr && errormsg[loop]==' ')
  181.         {
  182.           setcr=FALSE;
  183.           errormsg[loop]='\n';
  184.         }
  185.       }
  186.     }
  187.     else
  188.     {
  189.       strcpy(errormsg,cantfind);
  190.     }
  191.  
  192.     if (ReqToolsBase)
  193.     {
  194.       if (myproc) ScreenToFront(scr);
  195.       rtEZRequest(errormsg,"OK!",NULL,NULL,NULL);
  196.     }
  197.     else
  198.       puts(errormsg);
  199.  
  200.     if (oldwinptr)
  201.       myproc->pr_WindowPtr=oldwinptr;
  202.     if (scr)
  203.       UnlockPubScreen(NULL,scr);
  204.     cleanup(0);
  205.   }
  206. }
  207.